package net.lainiao.morethread.Chapter4.demo8;

import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/3/3.
 */
public class Main {
    public static void main(String[] args) {
        ThreadPoolExecutor executor=(ThreadPoolExecutor) Executors.newCachedThreadPool();
        Task task=new Task();
        System.out.println("main:Executing the task");
        Future<String> result=executor.submit(task);
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Main: Canceling the task");
        result.cancel(true);
        System.out.println("Main: Canceled "+result.isCancelled());
        System.out.println("Main: Done "+result.isDone());
        executor.shutdown();
        System.out.println("Main: The executor has finished");
    }
}
